package com.zelin.seckill.service;

import org.springframework.context.annotation.Primary;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * 功能: 此类的作用，就是得到登录成功后的用户名，再通过用户名查询数据库，得到用户的一系列信息
 * 进而来判断用户的访问权限及角色。
 * 参数:
 * 返回值:
 * 时间: 2021/8/11 17:14
 */
@Component
@Primary
public class UserDetailsServiceImpl implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        return new User(username, "123", true, true, true, true,
                AuthorityUtils.createAuthorityList("ROLE_user","ROLE_admin"));
    }
}